package com.wuba.rxjavademo.tzx.create;

import com.wuba.rxjavademo.tzx.common.Base;
import com.wuba.rxjavademo.tzx.common.SimpleSubscriber;

import java.util.concurrent.TimeUnit;

import rx.Observable;

/**
 * Created by tanzhenxing
 * Date: 2016/6/24.
 * Description:
 * timer:一段时间之后发射。timer(long delay, TimeUnit unit)，
 * timer:一段时间之后执行轮询发射。timer(long initialDelay, long period, TimeUnit unit)
 */
public class RxTimer extends Base {
    public static void main(String [] args) {
        RxTimer timer = new RxTimer();
        timer.run();
        try {
            print("--mainThread=" + Thread.currentThread().getId());
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        Observable.timer(1,1, TimeUnit.SECONDS)
                .subscribe(new SimpleSubscriber<Long>(){
                    @Override
                    public void onNext(Long aLong) {
                        super.onNext(aLong);
                        print("--currentThread=" + Thread.currentThread().getId());
                        print(aLong);
                    }
                });
    }
}
